﻿@using Abp.Authorization.Users;
@using FwProject.Web.Startup;
@using FwProject.Restaurant.Dto;
@using FwProject.Core.Restaurant;
@model FwProject.Restaurant.Dto.RestaurantInputDto
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Content/bootstrap-tagsinput.css" rel="stylesheet" />
    <link href="~/plugins/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Theme/css/plugins/steps/jquery.steps.css" rel="stylesheet" />

}
<style>
    .content {
        height: 720px;
    }

    .control-label {
        padding: 0;
    }
</style>
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>修改餐厅信息 <small></small></h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content">
                <form id="form0" class="form-horizontal" action="/Restaurant/EditRestaurant?id=@ViewBag.Id" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="ReloadAjaxCallbackgoback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form">
                    <h1>餐厅资料</h1>
                    <fieldset style="width:100%">
                        <div>
                            <div class="col-lg-7">
                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.EmployeeDriverid, new { @class = "control-label col-md-3" })
                                        @Html.TextBoxFor(o => o.EmployeeDriverid, new { @class = "hidden" })
                                        <div class="col-lg-9">
                                            <div class="input-group">
                                                <input type="text" id="dropdown-driverid" class="form-control" value="@Model.DriveridName">
                                                <div class="input-group-btn">
                                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown" style="padding: 6px 12px;">
                                                        <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu dropdown-menu-right" id="r" role="menu" style="z-index: 9999;"></ul>
                                                </div>

                                            </div>
                                        </div>
                                        @Html.ValidationMessageFor(o => o.EmployeeDriverid)
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.RestaurantAddress, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            @Html.TextBoxFor(o => o.RestaurantAddress, new { @class = "form-control" })
                                            @Html.ValidationMessageFor(o => o.RestaurantAddress)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.RestaurantName, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            @Html.TextBoxFor(o => o.RestaurantName, new { @class = "form-control", placeholder = "餐厅名称" })
                                            @Html.ValidationMessageFor(o => o.RestaurantName)
                                        </div>
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            @Html.TextBoxFor(o => o.RestaurantName, new { @class = "form-control", placeholder = "餐厅名称" })
                                            @Html.ValidationMessageFor(o => o.RestaurantName)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.ChargeWay, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            <enums class="form-control" asp-name="ChargeWay" asp-valuetype="1" asp-enum="typeof(ChargeWayEnum)" asp-value="@Model.ChargeWay.ToString()"></enums>
                                            @Html.ValidationMessageFor(o => o.ChargeWay)
                                        </div>
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.BalanceWay, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            <enums class="form-control" asp-name="BalanceWay" asp-valuetype="1" asp-enum="typeof(BalanceWayEnum)" asp-value="@Model.BalanceWay.ToString()"></enums>
                                            @Html.ValidationMessageFor(o => o.BalanceWay)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.BalanceCycle, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            <enums class="form-control" asp-name="BalanceCycle" asp-valuetype="1" asp-enum="typeof(BalanceCycleEnum)" asp-value="@Model.BalanceCycle.ToString()"></enums>
                                            @Html.ValidationMessageFor(o => o.BalanceCycle)
                                        </div>
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.IsDiscontinuation, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9" style="line-height:3;">
                                            <BoolSelect asp-value="@Model.IsDiscontinuation" asp-name="IsDiscontinuation" class="form-control"></BoolSelect>
                                            @Html.ValidationMessageFor(o => o.IsDiscontinuation)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.Deposit, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            <div class="input-group">
                                                <div class="input-group-addon">￥</div>
                                                @Html.TextBoxFor(o => o.Deposit, new { @class = "form-control", @readonly = "readonly" })
                                                @Html.ValidationMessageFor(o => o.Deposit)
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.DepositDate, new { @class = "control-label col-md-3" })
                                        <div class="input-group date col-md-9">
                                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                            <span style="position: relative;">
                                                @Html.TextBoxFor(o => o.DepositDate, new { @class = "form-control", style = "padding:0 15px;", Value = DateTime.Now.ToString("yyyy-MM-dd") })
                                            </span>
                                            @Html.ValidationMessageFor(o => o.DepositDate)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.Label("", "经纬度", new { @class = "control-label col-md-3" })
                                        <div class="col-md-4">
                                            @Html.TextBoxFor(o => o.longitude, new { @class = "form-control", @readonly = "readonly", placeholder = "经度" })
                                            @Html.ValidationMessageFor(o => o.longitude)
                                        </div>
                                        <div class="col-md-4">
                                            @Html.TextBoxFor(o => o.latitude, new { @class = "form-control", @readonly = "readonly", placeholder = "纬度" })
                                            @Html.ValidationMessageFor(o => o.latitude)
                                        </div>
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.Label("", "期初店存", new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            @Html.TextBoxFor(o => o.Stock, new { @class = "form-control", placeholder = "" })
                                            @Html.ValidationMessageFor(o => o.Stock)
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.Thump, new { @class = "control-label col-md-2" })
                                        <div class="col-md-4">
                                            <button type="button" class="layui-btn" id="test1">
                                                <i class="layui-icon">&#xe67c;</i>上传图片
                                            </button>
                                            <span id="Thump_info"></span>
                                            @Html.TextBoxFor(o => o.Thump, new { @class = "hidden" })
                                            @Html.ValidationMessageFor(o => o.Thump)
                                        </div>
                                    </div>
                                    <div class="col-lg-6">
                                        @Html.LabelFor(o => o.RemarkContent, new { @class = "control-label col-md-3" })
                                        <div class="col-md-9">
                                            @Html.TextAreaFor(o => o.RemarkContent, new { @class = "form-control" })
                                            @Html.ValidationMessageFor(o => o.RemarkContent)
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-md-2"></label>
                                    <div class="col-md-4">
                                        <img id="Thump_img" style="max-width: 170px;" src="@(string.IsNullOrEmpty(Model.Thump)?"/images/photo_3.jpg":Url.Content(Model.Thump))" class="img-responsive" onerror="this.src='/images/photo_3.jpg'" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-lg-2">餐厅联系人：</label>
                                    <div class="col-lg-3">
                                        <div class="input-group">
                                            <input type="text" id="dropdown-restaurantUrse" class="form-control" value="@(string.Join(',',Model.RestaurantUsers.Select(o=>o.EmployeeRestauranUser.Name).ToArray()))">
                                            <div class="input-group-btn">
                                                <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown" style="padding: 6px 12px;">
                                                    <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu dropdown-menu-right" role="menu" style="z-index: 9999;"></ul>
                                            </div>
                                            <!-- /btn-group -->
                                        </div>
                                        <input class="hidden" type="hidden" name="RestaurantUserInputs" id="RestaurantUserInputs" value="@(string.Join(',',Model.RestaurantUsers.Select(o=>o.EmployeeRestaurantId).ToArray()))" />
                                        @*@Html.TextBoxFor(o => o.RestaurantUserInputs, new { @class = "hidden" })*@
                                        @Html.ValidationMessageFor(o => o.RestaurantUserInputs)
                                    </div>
                                    @*<div class="col-lg-5">
                                            @Html.TextBoxFor(o => o.RestaurantUserInputs, new { @class = "form-control" })&nbsp;&nbsp;&nbsp;
                                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 第一位为餐厅主要负责人</span>
                                            @Html.ValidationMessageFor(o => o.RestaurantUserInputs)
                                        </div>*@
                                </div>
                            </div>
                            <div class="col-lg-5">
                                <div class="form-group" style="margin-top:15px;">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h5 class="panel-title">
                                                <a data-toggle="collapse" data-parent="#accordion" href="tabs_panels.html#collapseOne">点击展开地图，选择餐厅坐标</a>
                                            </h5>
                                        </div>
                                        <div id="collapseOne" class="panel-collapse collapse in">
                                            <div class="panel-body">
                                                <div id="allmap" style="height:400px;width:100%;margin-top:15px;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <h1>餐厅绑定型号</h1>
                    <fieldset style="width:100%">
                        <div id="divNumber">
                            @if (Model.TypenNumberInfos != null && Model.TypenNumberInfos.Count > 0)
                            {
                                for (int i = 0; i < Model.TypenNumberInfos.Count; i++)
                                {
                                    <div>
                                        <div class="form-group">
                                            <label class="control-label col-md-1">餐厅型号</label>
                                            <div class="col-md-5">
                                                @Html.DropDownListFor(o => o.TypenNumberInfos[i].TypeNumberId, ViewBag.TypeNumbers as IEnumerable<SelectListItem>
                                                    , new { @class = "form-control numbrs" })
                                                @Html.HiddenFor(o => o.TypenNumberInfos[i].Id)
                                                @Html.ValidationMessageFor(o => o.TypenNumberInfos[i].TypeNumberId)
                                            </div>
                                            <a class='btn btn-danger btn-xs' onclick='deltypeNumber(this)' style='margin-top: 7px;'><i class='fa fa-times'></i>删除</a>
                                        </div>
                                        <div class="form-group">
                                            @Html.LabelFor(o => o.TypenNumberInfos[i].Price, new { @class = "control-label col-md-1" })
                                            <div class="col-md-5">
                                                @Html.TextBoxFor(o => o.TypenNumberInfos[i].Price, new { number = "number", @class = "form-control" })
                                                @*<input type="number" class="form-control" name="TypenNumberInfos[i].Price" value="0" />*@
                                            </div>
                                        </div>
                                    </div>
                                }
                            }
                        </div>
                        <div class="form-group" id="contact1">
                            <label class="col-md-3"></label>
                            <button class="btn btn-success " onclick="AddNumber()" type="button">
                                <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;<span class="bold">添加型号</span>
                            </button>
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="type_html">
    <div>
        <div class="form-group">
            <label class="control-label col-md-1">餐厅型号</label>
            <div class="col-md-5">
                @Html.DropDownList("TypenNumberInfos[0].TypeNumberId", ViewBag.TypeNumbers as IEnumerable<SelectListItem>, new { @class = "form-control numbrs" })
            </div>
            <a class='btn btn-danger btn-xs' onclick='deltypeNumber(this)' style='margin-top: 7px;'><i class='fa fa-times'></i>删除</a>
        </div>
        <div class="form-group">
            <label class="control-label col-md-1">单价</label>
            <div class="col-md-5">
                <input type="number" class="form-control" name="TypenNumberInfos[0].Price" value="1" />
            </div>
        </div>
    </div>
</script>

@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Scripts/bootstrap-tagsinput.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/Scripts/jquery.treegrid.min.js"></script>
    <script src="~/plugins/layui/layui.js"></script>
    <script src="~/Theme/js/plugins/staps/jquery.steps.js"></script>
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=9zWs3Nt7FMrZDlqwUp3ZWm3W7pmrpGHI"></script>

    <script type="text/javascript">
        var url = "/uploads/temp/restaurantInfo/";
        layui.use('upload', function () {
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                , url: '/Restaurant/UploadImage' //上传接口
                , done: function (res) {
                    if (res.success) {
                        $('#Thump_info').html(res.result);
                        $('#Thump').val(res.result);
                        $('#Thump_img').attr("src", url+res.result)
                    }
                }
                , error: function () {
                    //请求异常回调
                }
            });
        });

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                top.closeAndRefreshTab("@Url.Action("Edit", new { id = Html.ViewContext.RouteData.Values["id"] })");
            }, successInfo);
        }


        var drivers;
        var restaurantUsers;

        $(document).ready(function () {


            //绑定司机
                $.getJSON("/Users/GetSuggestData?type=司机类型&factoryinfoId=@ViewBag.FactoryinfoId").done(function (data) {
                    CommonAjaxCallback(data, function () {
                            drivers = data.result;
                            bindSuggest(drivers);
                    }, null);
                }).fail(function () {
                    layer.msg('连接超时，获取司机信息失败！', {
                        icon: 2,
                        time: 2000
                    });
                });

            //绑定餐厅人员
            $.getJSON("/Users/GetSuggestData?type=餐厅老板类型").done(function (data) {
                CommonAjaxCallback(data, function () {
                    restaurantUsers = data.result;

                    binDrestaurantSuggest(restaurantUsers);
                }, null);
            }).fail(function () {
                layer.msg('连接超时，获取餐厅员工信息失败！', {
                    icon: 2,
                    time: 2000
                });
            });


             //百度地图
            var map = new BMap.Map("allmap");
            var point = new BMap.Point('@Model.longitude', '@Model.latitude');
            var marker = new BMap.Marker(point);  // 创建标注
            map.addOverlay(marker);              // 将标注添加到地图中

            map.centerAndZoom(point, 11);
            function showInfo(e) {
                $("#longitude").val(e.point.lng);
                $("#latitude").val(e.point.lat);
                //alert(e.point.lng + ", " + e.point.lat);
            }
            map.enableScrollWheelZoom(true);
            map.addEventListener("click", showInfo);

            var local = new BMap.LocalSearch(map, {
                renderOptions: { map: map }
            });

            $('#RestaurantAddress').on("input", function () {
                var t = $(this).val();
                local.search(t);
            })

            //$('.bootstrap-tagsinput input').width(1);

            $(".date input").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !1, autoclose: !0 });
            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });



            @*$('#RestaurantUserInputs').tagsinput({
                confirmKeys: [13, 44],
                //freeInput: false,
                trimValue: true,
                itemValue: function (item) {
                    return item.id;
                },
                itemText: function (item) {
                    return item.name;
                }
            });
            $('.bootstrap-tagsinput input').hide();
                 @if (Model.RestaurantUsers != null) {
                foreach (var user in Model.RestaurantUsers)
                {

                 if (user.EmployeeRestauranUser != null) {
                <text>
                       $('#RestaurantUserInputs').tagsinput('add', {id:@(user.EmployeeRestauranUser.Id),name:"@(user.EmployeeRestauranUser.Name)"});
                </text>
                    }
                     }
                 }*@

        });
            var t=  $("#form0").steps({
                labels:{finish:"保存",next:"下一步",previous:"上一步"},
                titleTemplate:"<span class=\"number\">第#index#步：</span> #title#",
                bodyTag: "fieldset", onStepChanging: function (event, currentIndex, newIndex) {
                    if (currentIndex > newIndex) {
                        return true
                    }
                    var form = $(this);
                    if (currentIndex < newIndex) {
                        $(".body:eq(" + newIndex + ") label.error", form).remove();
                        $(".body:eq(" + newIndex + ") .error", form).removeClass("error")
                    }
                    return form.valid()
                }, onStepChanged: function (event, currentIndex, priorIndex) {

                    if (currentIndex ==4) {
                        enableFinishButton:true;
                    }
                }, onFinishing: function (event, currentIndex) {
                    var form = $(this);
                    return form.valid();
                }, onFinished: function (event, currentIndex) {
                    var form = $(this);
                    form.submit();
                }
            });


        function bindSuggest(data) {
            if ($("#dropdown-driverid") != undefined) {
                $role = $("#dropdown-driverid").bsSuggest({
                    effectiveFields: ["name"],
                    effectiveFieldsAlias: { "name": "姓名" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#EmployeeDriverid").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }

        function binDrestaurantSuggest(data) {
            if ($("#dropdown-restaurantUrse") != undefined) {
                $role = $("#dropdown-restaurantUrse").bsSuggest({
                    effectiveFields: ["name","mobile"],
                    effectiveFieldsAlias: { "name": "姓名","mobile":"电话"},
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    //$('#RestaurantUserInputs').tagsinput('add', data);
                    $('#RestaurantUserInputs').val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }


        function AddNumber() {
            var co = $('#divNumber').find('.numbrs');
            var length = co.length;
            var t = $('#type_html').html();
            t = t.replace(/TypenNumberInfos\[0\]/g, "TypenNumberInfos[" + length+"]");

            //h = h.replace(/ProductIds\[0\]/g, "ProductIds[" + l + "]");
            $('#divNumber').append(t);

            $("form").removeData("validator").removeData("unobtrusiveValidation");
            $.validator.unobtrusive.parse("form");
        }

        function deltypeNumber(obj) {
            $(obj).parent().parent().remove();
        }




    </script>
}



